// FunkyDog MailBundle - tags and keywords for Apple Mail 3.0
//    Copyright (C) 2008 saptarshi guha saptarshi.guha@gmail.com
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.


#import "SearchSliceView-Extras.h"
#import "FunkyDog.h"
#import <objc/objc.h>
#import <objc/objc-runtime.h>
#import <objc/objc-class.h>

@implementation SearchSliceView(Extras)
+(void)load{
	if (self == [SearchSliceView class]){
		Method originalMethod ,replacedMethod;
	//	originalMethod  = class_getInstanceMethod(self, @selector(_addButtonForSearchField:inArea:)); //Called 1st
	//	replacedMethod  = class_getInstanceMethod(self, @selector(my_addButtonForSearchField:inArea:));
	//		method_exchangeImplementations(originalMethod, replacedMethod);
	//	originalMethod  = class_getInstanceMethod(self, @selector(_setupView)); //Called 1st
	//	replacedMethod  = class_getInstanceMethod(self, @selector(my_setupView));
	//		method_exchangeImplementations(originalMethod, replacedMethod);
		originalMethod  = class_getInstanceMethod(self, @selector(_layoutItems)); //Called 1st
		replacedMethod  = class_getInstanceMethod(self, @selector(my_layoutItems));
		method_exchangeImplementations(originalMethod, replacedMethod);

		originalMethod  = class_getInstanceMethod(self, @selector(searchFieldButtonAction:)); //Called 1st
		replacedMethod  = class_getInstanceMethod(self, @selector(mysearchFieldButtonAction:));
		method_exchangeImplementations(originalMethod, replacedMethod);
		
	}
}
-(void)mysearchFieldButtonAction:(id)sender{
//	NSLog(@"[SearchSliceView mysearchFieldButtonAction:%@",sender);
	if([sender tag]==TAGTAG) [[FunkySob sharedInstance] setTagSearch:YES]; else [[FunkySob sharedInstance] setTagSearch:NO];
	if([sender tag]==NOTETAG) [[FunkySob sharedInstance] setNoteSearch:YES]; else [[FunkySob sharedInstance] setNoteSearch:NO];
	if([sender tag]==STEROIDTAG) [[FunkySob sharedInstance] setSteroidSearch:YES]; else [[FunkySob sharedInstance] setSteroidSearch:NO];
	[self mysearchFieldButtonAction:sender];
}
//-(void)my_setupView{
//	[self my_setupView];
//} 
//-(void)my_addButtonForSearchField:(int)fp8 inArea:(int)fp12{
//	[self my_addButtonForSearchField:fp8 inArea:fp12];
//}
-(void)my_layoutItems{
	//NSLog(@"[SearchSliceView _layoutItems]");
	if([_fieldButtons count]<=4){ //why 4?
	NSButton *b0=[_fieldButtons objectAtIndex:[_fieldButtons count]-1];
	NSButton *b1=[self createSearchButton];
	[b1 setTitle:@"Tags"];
	[b1 setTarget:self];
	[b1 setAction:@selector(searchFieldButtonAction:)];
	[b1 setFrameSize:[b0 frame].size];
		[b1 setTag:TAGTAG];
	[self addSubview:b1];
	[_fieldButtons addObject:b1];
	
	b0=[_fieldButtons objectAtIndex:[_fieldButtons count]-1];
	b1=[self createSearchButton];
	[b1 setTitle:@"Notes"];
	[b1 setTarget:self];
	[b1 setAction:@selector(searchFieldButtonAction:)];
	[b1 setFrameSize:[b0 frame].size];
	[b1 setTag:NOTETAG];
	[self addSubview:b1];
	[_fieldButtons addObject:b1];
	
	b0=[_fieldButtons objectAtIndex:[_fieldButtons count]-1];
	b1=[self createSearchButton];
	[b1 setTitle:@"Steroids"];
	[b1 setTarget:self];
	[b1 setAction:@selector(searchFieldButtonAction:)];
	[b1 setFrameSize:[b0 frame].size];
	[b1 setTag:STEROIDTAG];
	[self addSubview:b1];
	[_fieldButtons addObject:b1];
	}

	[self my_layoutItems];
	
	
}
@end
